package org.aeon.gamechatnest.configuration.thread;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author MissingAeon
 * @date 2024/5/20 10:56
 * @description
 */
@Slf4j
@Configuration
public class MessageSendThreadConfiguration {

    @Autowired
    private ThreadPoolExecutor executor;

    @Resource
    private MessageSendHandler messageSendHandler;

    @Bean("messageSendThread")
    public MessageSendHandler messageSendThread() {
        log.debug("创建了消息发送线程...");
        if (!messageSendHandler.isRunning()) {
            executor.execute(messageSendHandler);
        }
        return messageSendHandler;
    }
}
